// 修改用户信息
<template>
    <div>
        <GoBack></GoBack>
        <div class="modifyBox">
            <p class="adselfBox">修改资料</p>
            <div class="modifyCont">
                <p class="userName">账户名<span>{{$store.state.userInfo.user_name}}</span></p>
                <div class="selcetBox flex flex-align-center">
                 <p class="queren">会员昵称</p>
                 <input type="text" placeholder="请输入会员昵称" v-model.trim="nickname">
                 <p class="nickName-tips">该昵称只适用于聊天</p>
                </div>
                 <div class="selcetBox flex flex-align-center">
                 <p>QQ号</p>
                 <input class="qqinput" type="text" placeholder="请输入QQ号" v-model.trim='qq'>
                </div>
                <div class="qrBtn flex flex-align-center flex-pack-center" @click="onModifyInfo"><p>确认修改</p></div>
            </div>
        </div>
    </div>
</template>
<script>
import GoBack from '../goback'
import https from '@/public/https'
export default {
    components: {
        GoBack
    },
    data () {
        return {
            nickname:'',
            qq:''
        }
    },
    methods: {
        onModifyInfo(){
            let uid = this.$store.state.userInfo.id;
            if(this.nickname != '' && this.qq != ''){
                if(this.isNickName()){
                    if(this.isQQ()){
                        https.post('user/postEditPersonalData',{uid:uid,nickname:this.nickname,qq:this.qq})
                        .then(data => {
                            if(data.status == 1){
                                this.$message({
                                        message:'修改成功',
                                        type: 'success'
                                });
                                this.nickname = '';
                                this.qq = '';
                            }else{
                                this.$message.error(data.message);
                            }
                        })
                    }else{
                        this.$message.error('qq号格式不正确');
                    }
                }else{
                    this.$message.error('会员昵称格式错误');
                }
            }
        },
        isQQ(){      
            var qq= this.qq;
            if (qq.search(/^[1-9]([0-9]{4,10})$/) != -1){  
                return true;   
            }
            else{
                return false;
            }
        },
        isNickName(){
            var name = this.nickname;
            if(name.search(/^[\u4E00-\u9FA5A-Za-z0-9]{2,11}$/) != -1){
               return true;   
            }
            else{
                return false;
            }
        }
    },
}
</script>
<style lang="less" scoped>
@import url(../../assets/css/usercenter/modifyuserinfo.less);
</style>


